package comxyp.interceptor;
import comxyp.common.Constant;
import comxyp.pojo.settings.Users;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//拦截器  实现 没有登录 不能访问其他页面
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断session是否为空
        if((request.getSession().getAttribute(Constant.user)==null)){
            //如果没有登录，则重定向去到登录页面
            response.sendRedirect(request.getContextPath()+"/global/login");
            return false;//验证失败，进行拦截
        }
        //验证通过
        return true;
    }
}
